#include "alarm.h"

rt_mailbox_t alarms;

void alarmd(void *arg){
    /*初始化蜂鸣器引脚*/
    rt_pin_mode(BEEP_PIN, PIN_MODE_OUTPUT);
    rt_pin_write(BEEP_PIN, PIN_LOW);

    /*初始化邮箱*/
    alarms = rt_mb_create("mbalarm", 4, RT_IPC_FLAG_FIFO);
    uint32_t alarm;

    while (1){
        rt_mb_recv(alarms, &alarm, RT_WAITING_FOREVER);
        for (int i=0; i<32; ++i){
            rt_pin_write(BEEP_PIN, !!(alarm&(1<<i)));
            rt_thread_mdelay(30);
        }
        rt_pin_write(BEEP_PIN, PIN_LOW);
    }
}
